package com.example.software.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.Getter;

@Getter
@JsonFormat(shape = JsonFormat.Shape.OBJECT)
public enum FirstMajorEnum {

    //14个一级分类 直接作为java内双值枚举 如 JiaoCha（14，交叉学科 ）

    ZUANYE1(1, "国语文"),
    YU_YAN(2, "语言"),
    YU_XIAO(3, "语小"),
    YU_ZHONG(4, "语中"),
    YU_DA(5, "语大"),
    YU_XIN(6, "语新"),
    YU_XIN_ZHONG(7, "语新中"),
    YU_XIN_DA(8, "语新大");


    private final Integer id;

    @JsonValue
    private final String name;

    FirstMajorEnum(Integer i, String name) {
        this.id = i;
        this.name = name;
    }
    public static FirstMajorEnum fromName(String value) {
        if (value == null) {
            return null;
        }
        for (FirstMajorEnum gender : FirstMajorEnum.values()) {
            if (gender.name().equalsIgnoreCase(value)) {
                return gender;
            }
        }
        return null;
    }

    //判断传来的key是否超出枚举的范围
    public static boolean isValid(Integer id) {
        if (id == null) {
            return false;
        }
        for (FirstMajorEnum gender : FirstMajorEnum.values()) {
            if (gender.getId().equals(id)) {
                return true;
            }
        }
        return false;
    }

    public static FirstMajorEnum fromId(Integer id) {
        if (id == null) {
            return null;
        }
        for (FirstMajorEnum gender : FirstMajorEnum.values()) {
            if (gender.getId().equals(id)) {
                return gender;
            }
        }
        throw new IllegalArgumentException("Invalid id: " + id);
    }

}
